package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import service.tAreaService;
import service.tUserService;

import com.opensymphony.xwork2.ActionContext;

import entity.tArea;
import entity.tUser;

public class GettUserDateToAlter {
	
	private String userId;
	private String userName;
	private String trueName;
	private String email;
	private String company;
	private String mobilePhone;
	private String phone;
	private String tAreaId;
	private String tAreaName;
	private String test;
	private tAreaService tareaService;
	private tUserService tuserService;
//	private tUser tuser;
	
	@SuppressWarnings("unchecked")
	public String get() throws IOException, ParseException{
		
		ActionContext context = ActionContext.getContext();  
	    HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);  
	    //HttpServletResponse response = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);  
	    @SuppressWarnings("unused")
		Map session = context.getSession(); 
		ServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		@SuppressWarnings("unused")
		PrintWriter out = response.getWriter();
		System.out.println("----------经过GettUserDateToAlter----------");
		
		request.getAttribute("userId");
		System.out.println(userId);
		
		List<tUser> tuser = (List<tUser>) tuserService.searchById(userId);
		
		userId = tuser.get(0).getUserId();
		userName = tuser.get(0).getUserName();
		trueName = tuser.get(0).getTrueName();
		email = tuser.get(0).getEmail();
	
		mobilePhone = tuser.get(0).getMobilePhone();
		phone = tuser.get(0).getPhone();
		tAreaId = tuser.get(0).gettAreaId();
		this.setTest("福建省");
		this.settAreaName("福建省");
		if (tAreaId == null || tAreaId.equals(null)){
			tAreaId = "FJ";
		}
		
		List<tArea> area = new ArrayList<tArea>();
		area = tareaService.searchById(tAreaId);
		
		//tAreaName = area.get(0).getName();
		
		
		List<tArea> lists = new ArrayList();
		JSONArray jsonArray = new JSONArray();
		
		List<tArea> tarea = new ArrayList<tArea>();
		
		tarea = tareaService.searchAll();
		System.out.println(tarea);
		 for (tArea tareas : tarea){
			JSONObject t = new JSONObject();
			
			String name = tareas.getName();
			System.out.println(name);
			System.out.println(tAreaName);
			if (! name.equals(tAreaName)){
				
				t.put("name", tareas.getName());
				//t.put("tAreaName", tAreaName);
				System.out.println(t);
				
				lists.add(tareas);
			}
			
			//jsonArray.add(t);
			
			
		 }
		 
		 request.setAttribute("lists",lists);
		
		System.out.println(tuser.get(0).getUserName());
		
		
		
		return "success";
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public tUserService getTuserService() {
		return tuserService;
	}

	public void setTuserService(tUserService tuserService) {
		this.tuserService = tuserService;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getTrueName() {
		return trueName;
	}

	public void setTrueName(String trueName) {
		this.trueName = trueName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String gettAreaId() {
		return tAreaId;
	}

	public void settAreaId(String tAreaId) {
		this.tAreaId = tAreaId;
	}

	public tAreaService getTareaService() {
		return tareaService;
	}

	public void setTareaService(tAreaService tareaService) {
		this.tareaService = tareaService;
	}

	public String gettAreaName() {
		return tAreaName;
	}

	public void settAreaName(String tAreaName) {
		this.tAreaName = tAreaName;
	}

	public String getTest() {
		return test;
	}

	public void setTest(String test) {
		this.test = test;
	}
	

}
